package util.apps.gump;

import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;


import javax.swing.*;
import util.gen.*;

public class GumpApplicationPanel  extends JPanel implements ComponentListener{
		
		//fields
		
		private int insetPadding = 5;
		private Insets topBottomInset = new Insets(insetPadding,0,insetPadding,0);
		private Insets leftRightInsets = new Insets(0,insetPadding,0,insetPadding);
		private Insets allSidesInset = new Insets(insetPadding,insetPadding,insetPadding,insetPadding);
		public static final Font FONT = new Font("Dialog",Font.PLAIN,12);
		private GumpDrawFrame frame;
		private int maxHeight = 0;

		
		public GumpApplicationPanel(Gump gump, GumpDrawFrame frame){
			this.frame = frame;
			
			//set layout and common constraints
			setLayout(new GridBagLayout());
			GridBagConstraints c = new GridBagConstraints();
			c.fill = GridBagConstraints.HORIZONTAL;
			c.anchor = GridBagConstraints.LINE_START;
			c.gridheight = 1;
			c.weighty = 0;
			c.insets = allSidesInset;
			int row = 0;
			int numberColumns = 3;
			setBackground(Color.WHITE);
			
			//Add title
			c.gridwidth = numberColumns;
			c.gridx = 0;
			c.gridy = row++;
			add(gump.getAppName(),c);
			
			//Add application description 
			c.gridwidth = numberColumns;
			c.gridx = 0;
			c.gridy = row++;
			add(gump.getAppDescriptionS(),c);
			
			//for each parameter
			Option[] options = gump.getOptions();
			c.gridwidth = 1;
			
			for (int i=0; i< options.length; i++){
				//input
				c.anchor = GridBagConstraints.CENTER;
				c.insets = leftRightInsets;
				c.weightx = 1;
				c.fill = GridBagConstraints.BOTH;
				c.gridy = row;
				c.gridx = 0;
				add(options[i].getUserInputS(),c);
				
				//flag
				c.insets = topBottomInset;
				c.weightx = 0;
				c.fill = GridBagConstraints.NONE;			
				c.gridy = row;
				c.gridx = 1;
				add(options[i].getFlagS(),c);
				
				//description
				c.anchor = GridBagConstraints.LINE_START;
				c.insets = allSidesInset;
				c.gridy = row;
				c.gridx = 2;
				add(options[i].getDescriptionS(),c);
				
				row++;
			}
			
			//add buttons
			c.fill = GridBagConstraints.NONE;
			c.anchor = GridBagConstraints.LINE_START;
			c.weightx = 0;
			c.insets = allSidesInset;

		}
		
		public void componentHidden(ComponentEvent e) {}
	    public void componentMoved(ComponentEvent e) {}
	    public void componentShown(ComponentEvent e) {}
	    
	    public void componentResized(ComponentEvent e) {
	        Dimension frameSize = frame.getSize();
	        Dimension panelSize = getPreferredSize();
	        panelSize.width = frameSize.width-20;
	        this.setPreferredSize(panelSize);
	    }

	    
	}